package com.kc.web.controller.business;

import com.google.common.collect.Maps;
import com.kc.business.service.IBizPlatformWalletService;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.utils.StringUtils;
import com.kc.framework.web.domain.server.Sys;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName BizPlatformWalletController
 * @Description TODO
 * @Author wangdongliang
 * @Date 2021/3/26 14:05
 */
@Slf4j
@RestController
@RequestMapping("/platformWallet")
public class BizPlatformWalletController extends BaseController {
    @Resource
    private IBizPlatformWalletService bizPlatformWalletService;
    /**
     * 钱包预览
     */
    @PreAuthorize("@ss.hasPermi('business:platformWallet:walletOverview')")
    @GetMapping(value = "/walletOverview")
    public AjaxResult walletOverview(Integer platformId,Integer type){
        //获取二级商户编号
        String subMchid = bizPlatformWalletService.getSubMchid(platformId,type);
        if(StringUtils.isEmpty(subMchid)){
            return AjaxResult.error("二级商户编号错误");
        }
        Map<String, BigDecimal> result = Maps.newHashMap();
        //总收入金额
        BigDecimal totalIncome = new BigDecimal("0.0");
        totalIncome = bizPlatformWalletService.getFinishOrderMoney(platformId,-type);
        //提现中金额
        BigDecimal withdrawing = bizPlatformWalletService.getWithdrawing(subMchid);
        //已提现金额
        BigDecimal withdrew = bizPlatformWalletService.getWithdraw(subMchid);
        //可提现金额
        BigDecimal canWithdraw = bizPlatformWalletService.getCanWithdraw(subMchid);
        result.put("totalIncome", totalIncome);
        result.put("canWithdraw", canWithdraw);
        result.put("withdrawing", withdrawing);
        result.put("withdrew", withdrew);
        return AjaxResult.success(result);
    }

    @PreAuthorize("@ss.hasPermi('business:platformWallet:walletList')")
    @GetMapping(value = "/walletList")
    public TableDataInfo walletList(Integer platformId,Integer type){
        //获取二级商户编号
        String subMchid = bizPlatformWalletService.getSubMchid(platformId,type);
//        if(StringUtils.isEmpty(subMchid)){
//            return AjaxResult.error("二级商户编号错误");
//        }
        startPage();
//        String subMchid = "1605858494";

        return getDataTable(bizPlatformWalletService.getWalletRecord(subMchid));
    }



}
